<?php
namespace Dev\Controller;
use Common\Model\GameModel;
use Dev\BaseController;
use Think\Controller;
class IndexController extends BaseController {
    public function index(){
        $gameKV=GameModel::getGameKv();
        $currentGame=$this->currentGame;
        $gamesArr=explode(',',session("games"));

        foreach ($gameKV as $k=>$v){
            if(!in_array($k,$gamesArr)){
                unset($gameKV[$k]);
            }
        }


        $this->smarty->assign('account',session("real_name"));
        $this->smarty->assign("games",$gameKV);
        $this->smarty->assign("currentGame",$currentGame);
        $this->smarty->display("index.html");
    }


    public function changeCurrentGame(){
        $game=I('post.gameId',null);
        $gameKv=GameModel::getGameKv();
        if(!array_key_exists($game,$gameKv)){
            $this->ajaxReturn(array("status"=>1,"msg"=>'错误的游戏'));
        }

        $games=explode(',',session('games'));
        if(!in_array($game,$games)){
            $this->ajaxReturn(array("status"=>1,"msg"=>$game.'指定的游戏未被授权'.session('games')));
        }


        session('game',$game);
        $this->ajaxReturn(array("status"=>0,"msg"=>'success','gameName'=>$gameKv[$game]));

    }
}